<script src="{{URL::asset('recommend/js/recommandinfo.js')}}"></script>
<!-- 上传头像名字  start -->
<div class="centerTop">
    <div class="centerTitle">
        <p>基础资料 <span> -- 修改你的数据分析师资料，将显示在推荐榜单界面当中</span></p>
    </div>
    <div class="centerPhoto">
        <div class="center_photo_left">
            <div>
                <img src="{{URL::asset('/recommend/images/nicheng.png')}}" alt="">
                <span>昵称</span>
                @if(count($tuijianStatus) == 0)
                    <input type="text" id="nickname">
                @else
                    <input type="text" id="nickname" disabled style="background: none;" value="{{ $tuijianStatus['nickname'] }}">
                    <a onclick="resetInfo(1)"><img src="{{URL::asset('/recommend/images/bianji.png')}}" alt=""></a>
                @endif
                
            </div>
            <div>
                <div style="text-align: left;">
                    <img src="{{URL::asset('/recommend/images/jianjie.png')}}" alt="">
                    <span>简介</span>
                </div>
                 @if(count($tuijianStatus) == 0)
                    <textarea id="nickBianji"></textarea>
                 @else
                    <textarea id="nickBianji"  disabled style="background: none;">{{ $tuijianStatus['intro'] }}</textarea>
                    <a href="javascript:;" onclick="resetInfo(2)"><img src="{{URL::asset('/recommend/images/bianji.png')}}" alt=""></a>
                 @endif
                
            </div>
            <br style="clear: both" />
            <div>
                @if(count($tuijianStatus) == 0)
                <a href="javascript:;" class="affirm"  id="confirm"  onclick="nameAjax(1)">确认</a>
                @else
                <a href="javascript:;" class="affirm"  id="update" style="display:none" onclick="nameAjax(2)">确认修改</a>
                @endif
            
            </div>
        </div>
        <div class="center_photo_right">
            <div>
                {{--<span id="preview">--}}
                    {{--<img src="{{URL::asset('/recommend/images/morentouxiang.png')}}" alt="">--}}
                {{--</span>--}}
                {{--<div>--}}
                    {{--<span id="j_upPhoto"><img src="{{URL::asset('/recommend/images/shangchuangtoux.png')}}" alt="">头像上传--}}
                       {{--<form id="uploadForm" action="upload.php" method="post" enctype="multipart/form-data" style="position:relative;">--}}
                            {{--<input id="fileImage" type="file" size="30" name="photo"  accept="image/jpeg,image/png,image/gif" onchange="imgPreview(this,'preview')" style="position: absolute;top: -24px;opacity: 0"/>--}}
                       {{--</form>--}}
                    {{--</span>--}}
                    {{--<br>--}}
                    {{--<span>您可以上传JPG、PNG格式的图片，图片大小不能超过2M</span>--}}
                {{--</div>--}}
            </div>
            <br style="clear: both;"/>
            <div class="photoAffirm">
                {{--<a href="javascript:;">确认</a>--}}
            </div>
        </div>
    </div>
</div>
<!-- 上传头像名字  end -->
<!-- recommendAnalySt start -->
<div class="bianji">
    <!--<form action="" id="issueSub">-->
        <div class="centerTitle">
            <p>推荐榜发布</p>
        </div>
        <div class="selestFen">
            <img src="{{URL::asset('/recommend/images/radius.png')}}" alt="">
            选择分析师
        </div>
        <div class="selectDetaile">
            @if($listidarr)
                @foreach($listidarr->analystarr as $vk=>$vv)
                    <div>
                        <span><img src="{{$vv->photo}}" alt=""><img src="{{ URL::asset('recommend/images/renzheng.png') }}" alt=""></span><div fenID="{{$vv->id}}" fenFangX="{{explode(',',$listidarr->direction)[$vk]}}"><p>{{$vv->username}}</p><p>行情分析师</p><p>{{explode(',',$listidarr->direction)[$vk] == 0 ? "正向":"反向"}}</p></div><a href="javascript:;" onclick="deleteSelectFen(this)"><img src="{{ URL::asset('recommend/images/clones.png') }}" alt=""></a>
                    </div>
                @endforeach
            @else
                <div>
                    <img src="{{ URL::asset('recommend/images/add.png') }}" alt="" onclick="BlckTanShow(this)">
                    <br/>
                    <div class="append">点击添加分析师</div>
                </div>
                <div>
                    <img src="{{ URL::asset('recommend/images/add.png') }}" alt="" onclick="BlckTanShow(this)">
                    <br/>
                    <div class="append">点击添加分析师</div>
                </div>
                <div>
                    <img src="{{ URL::asset('recommend/images/add.png') }}" alt="" onclick="BlckTanShow(this)">
                    <br/>
                    <div class="append">点击添加分析师</div>
                </div>
            @endif
        </div>
        <br style="clear: both"/>
        <!-- 分析师搜索展示 end -->
        <div class="selestFen">
            <img src="{{URL::asset('/recommend/images/radius.png')}}" alt="">
            编辑内容
        </div>
        <textarea name="" id="textareaCon">@if($listidarr){{$listidarr->content}}@endif</textarea>
        <div class="upPhoto">
            @if($listidarr)
                @foreach(explode(",",$listidarr->photo) as $pk=>$pv)
                    <span @if($pk == 0) id="previewOne" @elseif($pk == 1) id="previewTwo" @else id="previewThree" @endif>
                        <div style="display: none;">
                            <form class="uploadForm" action="{{url('uploadimg')}}" method="post" enctype="multipart/form-data" @if($pk == 0) id="previewOne" @elseif($pk == 1) id="previewTwo" @else id="previewThree" @endif>
                                <input class="fileImage" type="file" size="30" name="image"  accept="image/*"  @if($pk == 0) onchange="imgPreview(this,'previewOne')" @elseif($pk == 1) onchange="imgPreview(this,'previewTwo')" @else onchange="imgPreview(this,'previewThree')" @endif style="position: absolute;top: 47px;opacity: 0;left: 0;margin: 0;"/>
                            </form>
                            <img src="{{URL::asset('/recommend/images/add.png')}}" alt="">
                            <p>点击添加图片</p>
                            <p>支持JPG/PNG格式</p>
                        </div>
                        <img src="{{ URL::asset('recommend/images/clones.png') }}" alt="" style="position: absolute;top: 0;right: 0;margin: 0;" @if($pk == 0) onclick="show('previewOne')" @elseif($pk == 1) onclick="show('previewTwo')" @else onclick="show('previewThree')" @endif/>
                        <img src="{{$pv}}" style="margin:0;width: 100%;height: 100%;" @if($pk == 0) class="previewOne" @elseif($pk == 1) class="previewTwo" @else class="previewThree" @endif/>
                    </span>
                @endforeach
            @else
                <span id="previewOne">
                    <div>
                        <form class="uploadForm" action="{{url('uploadimg')}}" method="post" enctype="multipart/form-data" id="previewOne">
                            <input class="fileImage" type="file" size="30" name="image"  accept="image/*" onchange="imgPreview(this,'previewOne')" style="position: absolute;top: 47px;opacity: 0;left: 0;margin: 0;"/>
                        </form>
                        <img src="{{URL::asset('/recommend/images/add.png')}}" alt="">
                        <p>点击添加图片</p>
                        <p>支持JPG/PNG格式</p>
                    </div>
                    <img src="{{ URL::asset('recommend/images/clones.png') }}" alt="" style="position: absolute;top: 0;right: 0;margin: 0;display: none" onclick="show('previewOne')"/>
                </span>
                <span id="previewTwo">
                    <div>
                        <form class="uploadForm" action="{{url('uploadimg')}}" method="post" enctype="multipart/form-data" id="previewTwo">
                            <input class="fileImage" type="file" size="30" name="image"  accept="image/*" onchange="imgPreview(this,'previewTwo')" style="position: absolute;top: 47px;opacity: 0;left: 0;margin: 0;"/>
                        </form>
                        <img src="{{URL::asset('/recommend/images/add.png')}}" alt="">
                        <p>点击添加图片</p>
                        <p>支持JPG/PNG格式</p>
                    </div>
                    <img src="{{ URL::asset('recommend/images/clones.png') }}" alt="" style="position: absolute;top: 0;right: 0;margin: 0;display: none" onclick="show('previewTwo')"/>
                </span>
                <span id="previewThree">
                <div>
                    <form class="uploadForm" action="{{url('uploadimg')}}" method="post" enctype="multipart/form-data" id="previewThree">
                        <input class="fileImage" type="file" size="30" name="image"  accept="image/*" onchange="imgPreview(this,'previewThree')" style="position: absolute;top: 47px;opacity: 0;left: 0;margin: 0;"/>
                        </form>
                    <img src="{{URL::asset('/recommend/images/add.png')}}" alt="">
                    <p>点击添加图片</p>
                    <p>支持JPG/PNG格式</p>
                </div>
                <img src="{{ URL::asset('recommend/images/clones.png') }}" alt="" style="position: absolute;top: 0;right: 0;margin: 0;display: none" onclick="show('previewThree')"/>
        </span>
            @endif
        </div>
        <div class="confirm" onclick="issueAjax()">
            发布
        </div>
    <!--</form>-->
</div>
<!-- 弹窗 start -->
<div class="TanKuang">
    <a href="javascript:;" class="clone" onclick="BlckTanHide()"><img src="{{ URL::asset('recommend/images/clonesss.png') }}" alt=""></a>
    <!-- search start -->
    <div class="search">
        <h1>选择分析师 - 勾选方向</h1>
        <div class="searchInput">
            <input type="text" placeholder="请输入分析师名称" onkeyup="search()" id="onKeySearch" autocomplete="off">
            <!--<a href="javascript:;" onclick="searchFen()"></a>-->
        </div>
        <div class="searchDiv">
        </div>
    </div>
    <!-- search end-->
    <!-- 分析师搜索展示 start -->
    <div class="FenSearch">
            {{--<span><img src="{{ URL::asset('recommend/images/add.png') }}" alt=""></span>--}}
            {{--<span>--}}
                {{--<p>哈哈哈哈</p>--}}
                {{--<p><img src="{{ URL::asset('recommend/images/zuanshi2.png') }}" alt="" style="margin-right: 6px;vertical-align: middle;" />认证分析师</p>--}}
            {{--</span>--}}
            {{--<span>正向</span>--}}
            {{--<span>反向</span>--}}
            {{--<span>确认</span>--}}
    </div>
    <span onclick="searchQueRen()" class="searchQue" id="searchQue">确认</span>
</div>
<!-- 弹窗 end -->
<div style="height: 300px;"></div>
<script>
    var listid = "{{$listid}}";//编辑发布id
    var addurl = "{{ url('/addrecommand') }}";
    var imgUploadUrl = "{{ url('/uploadimg') }}";
    var searchUrl   = "{{url('/selectuser')}}",  // 搜索接口
        Photo       = '',  // 分析师头像
        FenName     = '',  // 分析师名字
        FenFang     = 2,   // 分析师反向
        FenId       = 0,   // 分析师id
        ObjectTan   = '',  // 弹窗公共html
        dataJia     = 0,   // 是否满足三个分析师提交发布
        FenArrId    = [],  // 分析师ID的数组
        FenArrFang  = [], // 方向
        recommUrl   = "{{url('/recomm')}}"; //上传的三张图片数组
    //编辑发布时分析师个数改为3（相当于已经能选择完分析师）
    if(parseInt(listid) != 0){
        {{--if((("{{$listidarr->analyst_id}}").split(",")).length == 3) {--}}
            dataJia = 3;
//        }
    }
    // 提交昵称，简介ajax,type=1:第一次填写   type=2:修改
    function nameAjax(type){
        var nickname   = $.trim($("#nickname").val()),
            nickBianji = $.trim($("#nickBianji").val());
        var nameReg = /^[\u4e00-\u9fff]{3,6}$/;
        var settuijianinfo = "{{url('/settuijianinfo')}}";
        if(nickname == '' || nickBianji == ''){
            layer.tips('昵称与简介不能为空', '#nickname');
            return false;
        }else if(!nameReg.test(nickname)){
            layer.tips('昵称必须为3-5为中文', '#nickname');
            return false;
        }else{
            $.ajax({
                url:settuijianinfo,
                type: 'post',
                data: {nickname:nickname,intro:nickBianji,type:type},
                dataType: "json",
                headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
                success: function(res){
                    if(res.code == 2){
                        $("#nickname").css('background','none');
                        $("#nickBianji").css('background','none');
                        $("#updateImg").css('background','block');
                        if(type == 1){
                            layer.tips('设置成功', '#nickname');
                           $("#confirm").css('display','none');
                            window.history.go(0);
                        }else{
                            layer.tips('修改成功', '#nickname');
                           $("#update").css('display','none');
                            window.history.go(0);
                        }
                        
                    }else if(res.code == 1){
                        layer.tips('昵称已被占用', '#nickname');
                    }else{
                        if(type == 1){
                            layer.tips('设置失败', '#nickname');
                        }else{
                            layer.tips('修改失败', '#nickname');
                        }
                    }
                }
            });
        }
    }
    // 搜索分析师
    $("#onKeySearch").blur(function(){
        setTimeout(function(){
            $('.searchDiv').hide();
        },500)
    });
    //搜索功能,提交ajax数据到后台
    function search(){
        var html ='',
            htmlFen = '',
            objStr = '';
        var firstLetter =  $.trim($("#onKeySearch").val());
        var datas = {'firstLetter': firstLetter};
        $('.searchDiv').show();
        var nameReg = /^[\u4e00-\u9fff]$/;
        if(nameReg.test(firstLetter)){
            $.ajax({
                url: searchUrl,
                data: datas,
                type: 'get',
                success: function (data) {
                    for(var i=0;i<data.length;i++){
                        objStr = "searchFenXi('"+data[i].username+"','"+data[i].photo+"','"+data[i].id+"')";
                        html+= '<p class="fenxishi" onclick="'+objStr+'">'+data[i].username+'</p>'
                    }
                    $('.searchDiv').html(html)//显示数据，同时覆盖上一次搜索的数据
                },
            });
        }
    }
    // 搜索分析师显示
    function searchFenXi(obj,photo,id){
        Photo = photo;
        FenName = obj;
        FenId = id;
        htmlFen = '<span><img src="'+photo+'" alt=""></span><span><p>'+obj+'</p><p><img src="{{ URL::asset('recommend/images/zuanshi2.png') }}" alt="" style="margin-right: 6px;vertical-align: middle;" />认证分析师</p></span><span onclick="activeShow(this,0)">正向</span><span onclick="activeShow(this,1)">反向</span>'
        $('.FenSearch').html(htmlFen)
        $('#searchQue').css('display','block');
    }
    // 删除图片
    function show(idne){
        $("#"+idne).children("img").eq(0).hide();
        $("#"+idne).children("img").eq(1).remove();
        $("#"+idne).children('div').show();
    }
    // 正向反向选择active
    function activeShow(obj,that){
        $(obj).siblings().removeClass();
        $(obj).attr({'class':'active'});
        FenFang = that;
    }
    // 分析搜索确认分析师
    function searchQueRen(){
        BlckTanHide();
        var fen = FenFang==0?"正向":"反向"
        if(FenFang == 2){
            layer.tips('请选择跟单反向', '.TanKuang');
            $('.TanKuang').show()
            return false;
        }else{
            var htmlSearch = '<span><img src="'+Photo+'" alt=""><img src="{{ URL::asset('recommend/images/renzheng.png') }}" alt=""></span><div fenID="'+FenId+'" fenFangX="'+FenFang+'"><p>'+FenName+'</p><p>行情分析师</p><p>'+fen+'</p></div><a href="javascript:;" onclick="deleteSelectFen(this)"><img src="{{ URL::asset('recommend/images/clones.png') }}" alt=""></a>'
            dataJia = dataJia+1;
            FenFang = 2;
            $(ObjectTan).parent().html(htmlSearch)
        }
    }
    // 弹窗显示
    function BlckTanShow(obj){
        ObjectTan = obj;
        $('#onKeySearch').val('')
        $('.FenSearch').html('');
        $('.TanKuang').show()
        $('#searchQue').css('display','none');
    }
    // 弹窗隐藏
    function BlckTanHide(){
        $('.TanKuang').hide()
    }
    // 删除选中分析师
    function deleteSelectFen(obj){
        var deleteHtml = '<img src="{{ URL::asset('recommend/images/add.png') }}" alt="" onclick="BlckTanShow(this)"><br/><div class="append">点击添加分析师</div>'
        $(obj).parent().html(deleteHtml);
        dataJia = dataJia - 1;
    }
    
    
    //type:1  重置昵称   2:重置简介
    function resetInfo(type){
        if(type == 1){
            $("#nickname").removeAttr('disabled');
            $("#nickname").css('background','#f5f5f5');
        }else if(type == 2){
            $("#nickBianji").removeAttr('disabled');
            $("#nickBianji").css('background','#f5f5f5');
        }
        $("#update").css('display','block');
        
    }
</script>
<!-- recommendAnalySt end -->



